/**
 * @author liangxi
 * @since 2023/12/21
 */

#ifndef DESIGNPATTERN_FORECASTDISPLAY_H
#define DESIGNPATTERN_FORECASTDISPLAY_H

#include <iostream>
#include "../Observer.h"
#include "../DisplayElement.h"

namespace Observer {

    class ForecastDisplay : public Observer, public DisplayElement {
    public:
        ForecastDisplay() = default;

        void display() override {
            std::cout << "Forecast:";
            if (currentPressure > lastPressure) {
                std::cout << "Improving weather on the way!" << std::endl;
            } else if (currentPressure == lastPressure) {
                std::cout << "More of the same" << std::endl;
            } else if (currentPressure < lastPressure) {
                std::cout << "Watch out for cooler, rainy weather" << std::endl;
            }
        }

        void update(float temp, float humidity, float pressure) override {
            lastPressure = currentPressure;
            currentPressure = pressure;
            display();
        }

    private:
        float currentPressure{29.92f};
        float lastPressure;

    };

} // Observer

#endif //DESIGNPATTERN_FORECASTDISPLAY_H
